package ok;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;

public class registerFrame extends JFrame {

    private JPanel contentPane;
    private JTextField idtext;
    public static LoginFrame loginframe;
    private JPasswordField passwordtext_1;
    private JPasswordField passwordtext_2;
    /**
     * Launch the application.
     */
    /**
     * Create the frame.
     */
    public registerFrame() {
        setTitle("\u6CE8\u518C");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

        setContentPane(contentPane);
        contentPane.setLayout(null);

        JLabel lblNewLabel = new JLabel("\u8D26\u53F7\uFF1A");
        lblNewLabel.setFont(new Font("楷体", Font.BOLD, 20));
        lblNewLabel.setBounds(70, 32, 73, 24);
        contentPane.add(lblNewLabel);

        JLabel lblNewLabel_1 = new JLabel("\u5BC6\u7801\uFF1A");
        lblNewLabel_1.setFont(new Font("楷体", Font.BOLD, 20));
        lblNewLabel_1.setBounds(70, 86, 73, 32);
        contentPane.add(lblNewLabel_1);

        JLabel lblNewLabel_2 = new JLabel("\u786E\u8BA4\u5BC6\u7801:");
        lblNewLabel_2.setFont(new Font("楷体", Font.BOLD, 20));
        lblNewLabel_2.setBounds(39, 145, 101, 32);
        contentPane.add(lblNewLabel_2);

        idtext = new JTextField();
        idtext.setBounds(153, 32, 182, 24);
        contentPane.add(idtext);
        idtext.setColumns(10);

        JButton btnNewButton = new JButton("\u53D6\u6D88");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                nregister(e);
            }
        });
        btnNewButton.setFont(new Font("宋体", Font.BOLD, 12));
        btnNewButton.setBounds(61, 207, 97, 32);
        contentPane.add(btnNewButton);

        JButton btnNewButton_1 = new JButton("\u786E\u8BA4");
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                register(e);
            }
        });
        btnNewButton_1.setFont(new Font("宋体", Font.BOLD, 12));
        btnNewButton_1.setBounds(284, 207, 97, 32);
        contentPane.add(btnNewButton_1);

        passwordtext_1 = new JPasswordField();
        passwordtext_1.setBounds(153, 86, 182, 24);
        contentPane.add(passwordtext_1);

        passwordtext_2 = new JPasswordField();
        passwordtext_2.setBounds(153, 145, 182, 24);
        contentPane.add(passwordtext_2);
    }

    protected void nregister(ActionEvent e) {
        // TODO Auto-generated method stub
        this.dispose();
        new LoginFrame().setVisible(true);;
    }

    protected void register(ActionEvent e) {
        // TODO Auto-generated method stub
        String a=idtext.getText();
        String b=passwordtext_1.getText();
        String c=passwordtext_2.getText();
        if(b.equals(c)) {
            LoginFrame loginframe=new LoginFrame();
            LoginFrame.user[LoginFrame.userLength]=new User(a,b);
            LoginFrame.userLength++;
            JOptionPane.showMessageDialog(this, "注册成功");
            this.dispose();
            loginframe.setVisible(true);
        }
        else
            JOptionPane.showMessageDialog(null, "两次密码输入不一致！", "提示",JOptionPane.ERROR_MESSAGE);

    }
}


